// 引入路由组件
// import Home from '@/views/Home';
// import Login from '@/views/Login';
// import Register from '@/views/Register';
// import Search from '@/views/Search';
// import Detail from '@/views/Detail'
// import AddCartSuccess from '@/views/AddCartSuccess'
// import ShopCart from '@/views/ShopCart'
// import Trade from '@/views/Trade'
// import Pay from '@/views/Pay'
// import PaySuccess from '@/views/PaySuccess'
// import Center from '@/views/Center'

// // 二级路由
// import GroupOrder from '@/views/Center/groupOrder'
// import MyOrder from '@/views/Center/myOrder'

export default [
  // 重定向 redirect，在项目跑起来是默认为/ 让他定向为 /Home 
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    // 动态加载， 懒加载
    component: ()=> import ('@/views/Home'),
    meta: { show: true }
  },
  {
    path: '/login',
    component: ()=>import('@/views/Login'),
    name: 'login',
    meta: { show: false }
  },
  {
    path: '/register',
    component:  ()=>import('@/views/Register'),
    meta: { show: false }
  },
  {
    name: 'search',
    path: '/search/:keyword?',
    component:  ()=>import('@/views/Search'),
    meta: { show: true }
  },
  {
    name: 'detail',
    path: '/detail/:skuId?',
    component:  ()=>import('@/views/Detail'),
    meta: { show: true }
  },
  {
    name: 'addCartSuccess',
    path: '/addcartsuccess',
    component:  ()=>import('@/views/AddCartSuccess'),
    meta: { show: true }
  },
  {
    name: 'shopCart',
    path: '/shopcart',
    component:  ()=>import('@/views/ShopCart'),
    meta: { show: true }
  },
  {
    name: 'trade',
    path: '/trade',
    component:  ()=>import('@/views/Trade'),
    beforeEnter: (to, from, next) =>{
      // 如果 是从购物车调过来  就放行
      if (from.path === '/shopcart') {
        console.log(1);
        next()
      }else{
        // 其他中断 则返回原来的 from
        next(false)
      }
    },
    meta: { show: true }
  },
  {
    name: 'pay',
    path: '/pay',
    component:  ()=>import('@/views/Pay'),
    beforeEnter: (to, from, next) =>{
      // 如果 是从购订单详细调过来  就放行
      if(from.path === '/trade') next()
      next(false)
    },
    meta: { show: true }
  },
  {
    name: 'paySuccess',
    path: '/paysuccess',
    component:  ()=>import('@/views/PaySuccess'),
    beforeEnter: (to, from, next) =>{
      // 如果 是从支付订单调过来  就放行
      if(from.path === '/pay') next()
      next(false)
    },
    meta: { show: true }
  },
  {
    path: '/center',
    component: ()=>import('@/views/Center'),
    children: [{
      name: 'groupOrder',
      path: 'grouporder',
      component:  ()=>import('@/views/Center/groupOrder')
    },
    {
      name: 'myOrder',
      path: 'myorder',
      component:  ()=>import('@/views/Center/myOrder')
    },
    {
      path: '/center',
      redirect: 'myorder'
    }],
    meta: { show: true }
  },
]